import pandas as pd
import os
import time
# 读取excel1的内容到excel2

inputDir = input("源文件夹:")
print('源文件夹', inputDir)
timed = 0.0
inputFile = ''
for root,dirs,files in os.walk(r""+inputDir):
    for file in files:
      #   print(os.path.join(root,file))
        full_path = os.path.join(root, file)
        mtime = os.stat(full_path).st_mtime
        # file_modify_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(mtime))
      #   print("{0} 修改时间是: {1}".format(full_path,file_modify_time))
      #   print(full_path,mtime,type(mtime))
        if mtime>timed:
           timed = mtime
           inputFile = full_path
print('获取到文件：', inputFile)

outputFile = input("目标文件:")
print('目标文件：', outputFile)
copyClm = input("复制源文件的哪几列:")
# print('从源文件的第几列开始复制：', inputFile)
copyClm = copyClm.split(',')
# method1转换元素为int
for index in range(len(copyClm)):
   copyClm[index]=int(copyClm[index])-1
copyToIndex = int(input("复制到目标文件，从第几列开始:"))+1
dataFrame = pd.read_excel(inputFile, sheet_name='Sheet1',usecols=copyClm)
# dataFrame = pd.read_excel(inputFile, sheet_name='Sheet1',usecols=(2,3,4))#, 获取第2,3,4列（从第0列开始计数）进行复制
dataFrame.to_excel(outputFile, sheet_name='Sheet1', startcol=int(copyToIndex), index=False) #从第2列开始写入
# dataFrame.to_excel('D:\\WILNEVKL\\新建.xls', sheet_name='Sheet1')
inputFile = input("输入任意退出:")
